package com.woniuxy.controller;


import com.woniuxy.controller.info.UserAndAccountInfo;
import com.woniuxy.model.RoleModel;
import com.woniuxy.service.RoleModelService;
import com.woniuxy.utils.MyException;
import com.woniuxy.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 马世亮
 * @since 2022-02-15
 */
@RestController
@RequestMapping("/roleModel")
@Api(tags = "用户角色接口")
public class RoleModelController {

    @Resource
    public RoleModelService roleModelService;

    @ApiOperation("获取所有角色信息")
    @PostMapping("/getAllRolemodel")
    public Result getAllRolemodel() throws MyException {

        List<RoleModel> list = roleModelService.list();
        if(null == list) throw new MyException(500,"角色信息获取失败");
        return Result.success(200,"查询成功",list);
    }

    @ApiOperation("是否已有权限")
    @PostMapping("/issave")
    public Result isOrnoSave(@RequestBody UserAndAccountInfo userAndAccountInfo){
        System.out.println(userAndAccountInfo);

        boolean b = roleModelService.isOrnot(userAndAccountInfo.getAccountId());
        if(!b) return Result.success(200,"无权限",b);
        return Result.fail(500,"已有权限");
    }

}

